package com.jinlia.show.modules.base.model.po;

import com.jinlia.show.modules.base.system.entity.SysRole;
import com.jinlia.show.modules.base.system.entity.SysRoleMenu;
import com.jinlia.show.modules.base.system.entity.SysUser;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.function.Supplier;

@Data
public class SysUserPO extends SysUser {


    /**
     * 用户的角色信息
     */
    private List<SysRole> roles;

    /**
     * 用户的菜单信息
     */
    private List<SysRoleMenu> roleMenus;
    /**
     * button的权限标识
     */
    private List<String> perms;

    /**
     * 性别标签
     *
     * @param genderLabel
     * @return
     */
    private String genderLabel;

    /**
     * 部门名称
     *
     * @param deptName
     * @return
     */
    private String deptName;


    public static SysUserPO fromEntity(SysUser sysUser) {
        SysUserPO sysUserVO = new SysUserPO();
        BeanUtils.copyProperties(sysUser, sysUserVO);
        return sysUserVO;
    }

    public static SysUser toEntity(SysUserPO sysUserVO) {
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(sysUserVO, sysUser);
        return sysUser;
    }

    public String getGenderLabel() {
//        if (this.genderLabel == null) {
//            //从数据字典中获取
//            genderLabel = CacheUtils.fromTable("name", "sys_dict", this.getGender());
//        }
        return genderLabel;

    }

    public String getDeptName() {
//        if (this.deptName == null) {
//            //从部门表中获取
//            deptName = CacheUtils.fromTable("name", "sys_dept", this.getDeptId());
//        }
        return deptName;

    }

    public void filedVO(Supplier<String>... methodReference) {
        for (Supplier<String> stringSupplier : methodReference) {
            stringSupplier.get();
        }
    }
}
